let initialState = {
  token: '',
  name: '',
  showLoginModal: false,
  loading: false,
};

const user = (state = initialState, action) => {
  switch (action.type) {
    case 'TOGGLE_LOADING':
      return { ...state, loading: action.payload };
    case 'TOGGLE_SHOWLOGINMODAL':
      return { ...state, showLoginModal: action.payload };
    case 'GET_USER_INFO':
      return {
        ...state,
        name: action.payload.name,
        token: action.payload.token,
      };
    case 'POST_USER_LOGIN':
      return {
        ...state,
        name: action.payload.name,
        token: action.payload.token,
      };
    case 'POST_USER_LOGOUT':
      return {
        ...state,
        name: '',
        token: '',
      };
    default:
      return state;
  }
};

export default user;
